package servlet;

import javax.servlet.*;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;

/**
 * @author MissChen
 * @date 2024年04月24日 10:50
 */
@WebServlet(urlPatterns = "/life3",initParams = {
        @WebInitParam(name="username",value="lili"),
        @WebInitParam(name="password",value="12345678")
})
public class LifeThreeServlet implements Servlet {
   private ServletConfig config;



    @Override
    public void init(ServletConfig config) throws ServletException {
        System.out.println("===============初始化方法=============");
        // System.out.println(config.getInitParameter("username"));
        // System.out.println(config.getInitParameter("password"));
        this.config=config;
    }

    @Override
    public ServletConfig getServletConfig() {
        return config;
    }


    public String getInitParameter(String key){
        return getServletConfig().getInitParameter(key);
    }
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        System.out.println("执行核心业务逻辑");
        // String username=getServletConfig().getInitParameter("username");
        // String password=getServletConfig().getInitParameter("password");
        String username=getInitParameter("username");
        String password=getInitParameter("password");
        System.out.println("username:"+username+",password="+password);

    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}
